package com.gzist.elderlyserviceplatform.controller.client;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gzist.elderlyserviceplatform.common.Result;
import com.gzist.elderlyserviceplatform.common.base.BaseDTO;
import com.gzist.elderlyserviceplatform.entity.dto.ElderlyInfoDto;
import com.gzist.elderlyserviceplatform.entity.po.ElderlyInfo;
import com.gzist.elderlyserviceplatform.service.ElderlyInfoService;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;

/**
 * 家庭老人信息表
 */
@RestController
@Tag(name = "家庭老人信息管理")
@RequestMapping("/api/client/elderlyInfo")
@RequiredArgsConstructor
public class ElderlyInfoControllerC {

    private final ElderlyInfoService elderlyInfoService;


    @PostMapping("/add")
    @Operation(summary = "老人信息添加")
    public Result add(
            @RequestBody
            @Parameter(description = "老人信息") ElderlyInfo elderlyInfo
    ){
        elderlyInfoService.saveElderly(elderlyInfo);
        return Result.success("添加成功");
    }


    @GetMapping("/detail/{id}")
    @Operation(summary = "根据id查询老人信息")
    public Result<ElderlyInfo> detail(
            @PathVariable
            @Parameter(description = "老人id") String id
    ){
        return Result.success(elderlyInfoService.getById(id),"查询成功");
    }

    @GetMapping("/delete/{id}")
    @Operation(summary = "根据id删除老人信息")
    public Result delete(
            @PathVariable
            @Parameter(description = "老人id") String id
    ){
        elderlyInfoService.removeById(id);
        return Result.success("删除成功");
    }

    @PostMapping("/batchDelete")
    @Operation(summary = "批量删除老人信息")
    public Result deleteBatch(
            @RequestBody
            @Parameter(description = "老人id集") String[] ids
    ){
        elderlyInfoService.removeByIds(Arrays.asList(ids));
        return Result.success("删除成功");
    }

    @PostMapping("/update")
    @Operation(summary = "根据对象id修改老人信息")
    public Result update(
            @RequestBody
            @Parameter(description = "老人信息") ElderlyInfo elderlyInfo
    ){
        elderlyInfoService.update(elderlyInfo);
        return Result.success("修改成功");
    }

    //用户查询关联的老人信息
    @PostMapping("/queryList")
    @Operation(summary = "用户询老人信息")
    public Result<Page<ElderlyInfo>> queryList(
            @RequestBody
            @Parameter(description = "查询参数") ElderlyInfoDto elderlyInfoDto
    ){
        return Result.success(elderlyInfoService.queryList(elderlyInfoDto),"查询成功") ;
    }
}